﻿using UnityEngine;
using FrameWorkSong;
using System.Collections.Generic;

public class ChangeMatrixMgr : MonoBehaviour
{
    public ChangePoint Zreo;
    public ChangePoint[] Points;
    public ChangePoint test;
    List<DoubleVector2> T;//转换后的点
    List<DoubleVector2> O;//转换前的点
    ChangeMatrixUtil changeMatrixUtil;
    public DoubleVector4 TMatrix;
    public DoubleVector4 OMatrix;
    /// <summary>
    /// 抽取坐标
    /// </summary>
    void ExtractionCoordinate()
    {
        T = new List<DoubleVector2>();
        O = new List<DoubleVector2>();
        int length = Points.Length;
        for (int i = 0; i < length; i++)
        {
            T.Add(Points[i].TPoint - Zreo.TPoint);
            O.Add(Points[i].OPoint - Zreo.OPoint);
        }
    }
    void Start()
    {
        ExtractionCoordinate();
        changeMatrixUtil = new ChangeMatrixUtil(T, O, 1);
        TMatrix = changeMatrixUtil.TMatrix;
        OMatrix = changeMatrixUtil.OMatrix;

        //test.TPoint = changeMatrixUtil.GetChangeVector(test.OPoint , changeMatrixUtil.TMatrix, Zreo.TPoint, Zreo.OPoint);
        DoubleVector2 vector = changeMatrixUtil.GetChangeVector(test.TPoint, changeMatrixUtil.OMatrix, Zreo.OPoint, Zreo.TPoint);
     //   Debug.Log(vector.x + "&" + vector.y);
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            ReadPiont();
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            test.TPoint= changeMatrixUtil.GetChangeVector(test.OPoint, changeMatrixUtil.TMatrix, Zreo.TPoint, Zreo.OPoint);
        }
    }
    void ReadPiont()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (Physics.Raycast(ray,out hit))
        {
            DoubleVector2 vector2 = changeMatrixUtil.GetChangeVector(GetVector(hit.point), changeMatrixUtil.TMatrix, Zreo.TPoint,Zreo.OPoint);
            Debug.Log(vector2.x+"/"+ vector2.y);
        }
    }
    DoubleVector2 GetVector(Vector3 vector3)
    {
        DoubleVector2 vector2 = new DoubleVector2(vector3.x, vector3.z);
        return vector2;
    }
}
